﻿using System;
using System.Collections.Generic;
using System.Text;
using Quartz;
using BaseLibrary;

namespace QuDao2Gtika
{
    public class GSMData : IJob
    {




        public void Execute(IJobExecutionContext context)
        {
            Do();
        }
        public string Do()
        {
            LogHelper Logger = new LogHelper();

            Logger.PlugName = "渠道提卡";

            PWMIS.DataProvider.Data.AdoHelper ado = PWMIS.DataProvider.Adapter.MyDB.GetDBHelper(PWMIS.Common.DBMSType.Oracle, DBHelper.getConnString("DYDB"));
            ado.CommandTimeOut = 20 * 60;
            string sql = "select allsql from quartz_sql_list t WHERE pluginname='QuDao2Gtika' ";
            string sqlmobile = "select mobile from quartz_sql_list t WHERE pluginname='QuDao2Gtika' ";
            string execsql = ado.ExecuteScalar(sql).ToString();//得到要执行的sql
            Logger.Info("原始" + execsql);

            foreach (string subsql in execsql.Split(';'))
            {
                string tmpsql = SQlProcess.DateProcess(subsql);
                if (!string.IsNullOrEmpty(tmpsql.Trim()))
                {
                    try
                    {
                        Logger.Info("执行" + tmpsql);
                        ado.ExecuteNonQuery(tmpsql);

                    }
                    catch (Exception e)
                    {
                        //短信通知错误
                        string targets=ado.ExecuteScalar(sqlmobile).ToString();
                        BaseLibrary.SMS.SendSMS(targets, tmpsql + e.Message);

                        Logger.Warn("错误" + tmpsql + e.Message);
                    }
                }
            }
            Logger.Info("END");
            return ado.ElapsedMilliseconds.ToString();
        }
    }
}
